package org.example;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;


import java.io.IOException;

public class TestHbase {

    static Admin admin = null;
    static Connection connection = null;

    private static void connectHbase() {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "192.168.88.101");
        // 获取连接对象
        try {

            connection = ConnectionFactory.createConnection(conf);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            admin = connection.getAdmin();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void close(Connection conn, Admin admin) throws IOException {
        if (conn != null) {
            conn.close();
        }
        if (admin != null) {
            admin.close();
        }
    }

    public static void main(String[] args) throws IOException {
        connectHbase();
        close(connection, admin);
    }

}
